<div class="row">
    <div class="col-md-12">
        <div class="portlet">
            <div class="portlet-title">
                <div class="caption">
                    <i class="fa fa-search"></i>
                    <strong><?=__('Users Search')?></strong>
                </div>
            </div>
            <div class="portlet-body">
                <form class="form-search form-inline">
                    <strong><?=__('Register At')?>:</strong>
                    <input type="text" class="form-control input-small date-picker" name="reg_time_from" size="8" value="<?=$filter['reg_time_from']?>" />
                    -
                    <input type="text" class="form-control input-small date-picker" name="reg_time_to" size="8" value="<?=$filter['reg_time_to']?>" />
                    &nbsp;
                    <strong>Email:</strong>
                    <input type="text" class="form-control" name="email" size="15" value="<?=$filter['email']?>" />
                    &nbsp;
                    <strong><?=__('Status')?>:</strong>
                    <select name="status" class="form-control">
                        <option value="0"><?=__('Select...')?></option>
                        <option value="NORMAL" <?=on($filter['status'] === 'NORMAL', 'selected')?>><?=strip_tags(__('NORMAL'))?></option>
                        <option value="LOCKED" <?=on($filter['status'] === 'LOCKED', 'selected')?>><?=strip_tags(__('LOCKED'))?></option>
                        <!--option value="APPLY"  <?=on($filter['status'] === 'APPLY',  'selected')?>><?=strip_tags(__('APPLY'))?></option>
                        <option value="REJECT" <?=on($filter['status'] === 'REJECT', 'selected')?>><?=strip_tags(__('REJECT'))?></option-->
                        <option value="LEAVED" <?=on($filter['status'] === 'LEAVED', 'selected')?>><?=strip_tags(__('LEAVED'))?></option>
                    </select>
                    &nbsp;
                    <strong><?=__('Department')?>:</strong>
                    <select name="dept_id" class="form-control">
                        <option value="0"><?=__('Select...')?></option>
                        <? foreach ($departments as $dept): ?>
                            <option value="<?=$dept['dept_id']?>" <?=on($filter['dept_id'] === $dept['dept_id'], 'selected')?>>
                                <?=str_repeat('&nbsp; ', $dept['level']*4)?>
                                <?=db_translate($dept['department'], 'department', $dept['dept_id'])?>
                            </option>
                        <? endforeach; ?>
                    </select>
                    &nbsp;
                    <strong><?=__('Role')?>:</strong>
                    <select name="role_id" class="form-control">
                        <option value="0"><?=__('Select...')?></option>
                        <? foreach ($roles as $role): ?>
                            <option value="<?=$role['role_id']?>" <?=on($filter['role_id'] === $role['role_id'], 'selected')?>>
                                <?=db_translate($role['description'], 'role', $role['role_id'])?>
                                <? if ($role['dept_id']): ?>
                                - [<?=OaDepartments::path2name($role['department']['depth_path'], ' / ')?>]
                                <? endif; ?>
                            </option>
                        <? endforeach; ?>
                    </select>
                    <button type="submit" class="btn green">
                            <i class="fa fa-search"></i>
                            <?=__('Search')?>
                    </button>
                </form>
            </div>
        </div>
        <div class="portlet">
            <div class="portlet-title">
                <div class="caption">
                    <i class="fa fa-list"></i>
                    <strong><?=__('Search Result')?></strong>
                </div>
                <div class="actions" style="margin-left:10px;">
                    <div class="btn-group">
                        <a class="btn default yellow-stripe" href="<?=url('user/create')?>">
                            <i class="fa fa-plus"></i> <?=__('Add User')?>
                        </a>
                    </div>
                </div>
                <? partial_view('pagination/small', array('extraClass' => 'pagination-sm')) ?>
            </div>
            <div class="portlet-body">
                <table class="table table-striped table-bordered table-hover margin-bottom-10">
                    <thead>
                        <tr class="heading">
                            <th width="50">ID</th>
                            <th>Email</th>
                            <th><?=__('Real Name')?></th>
                            <th><?=__('Register At')?></th>
                            <th><?=__('Last Visited')?></th>
                            <th><?=__('Department')?></th>
                            <th><?=__('Role')?></th>
                            <th width="60"><?=__('Status')?></th>
                            <th width="180"><?=__('Actions')?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <? foreach ($page->items as $item): ?>
                        <tr>
                            <td><?=$item->user_id?></td>
                            <td><?=highlight_keyword($item->email, $filter['email'])?></td>
                            <td><?=OaUsers::getRealName($item)?></td>
                            <td>
                                <?=on($item->reg_time, date('Y/m/d H:i', $item->reg_time), '-')?>
                                /
                                <?=on(ip2long($item->reg_ip), $item->reg_ip, '-')?>
                            </td>
                            <td>
                                <?=on($item->last_time, date('Y/m/d H:i', $item->last_time), '-')?>
                                /
                                <?=on(ip2long($item->last_ip), $item->last_ip, '-')?>
                            </td>
                            <td>
                                <? $depts = OaUsers::getDepartments($item->user_id); ?>
                                <? if ($depts): ?>
                                    <? foreach ($depts as $dept): ?>
                                        <a href="<?=url_param(null, array('dept_id' => $dept['dept_id']))?>" class="btn btn-xs dark">
                                            <?=db_translate($dept['department'], 'department', $dept['dept_id'])?>
                                        </a>
                                    <? endforeach; ?>
                                <? else: ?>
                                    -
                                <? endif; ?>
                            </td>
                            <td>
                                <? $roles = OaUsers::getRoles($item->user_id); ?>
                                <? if ($roles): ?>
                                    <? foreach ($roles as $role): ?>
                                        <a href="<?=url_param(null, array('role_id' => $role['role_id']))?>" class="btn btn-xs dark">
                                            <?=db_translate($role['description'], 'role', $role['role_id'])?>
                                        </a>
                                    <? endforeach; ?>
                                <? else: ?>
                                    -
                                <? endif; ?>
                            </td>
                            <td>
                                <?=__($item->status)?>
                            </td>
                            <td>
                                <a href="<?=url('user/edit/'.$item->user_id)?>" class="btn btn-xs default">
                                    <i class="fa fa-pencil"></i> <?=__('Edit')?>
                                </a>
                                <? if ($item->status === OaUsers::LOCKED): ?>
                                    <a href="<?=url('user/status/'.$item->user_id)?>?status=<?=OaUsers::NORMAL?>" class="btn btn-xs default ajax-link">
                                        <i class="fa fa-unlock"></i> <?=__('Unlock')?>
                                    </a>
                                <? else :?>
                                    <a href="<?=url('user/status/'.$item->user_id)?>?status=<?=OaUsers::LOCKED?>" class="btn btn-xs default ajax-link">
                                        <i class="fa fa-lock"></i> <?=__('Lock')?>
                                    </a>
                                <? endif; ?>
                                <? if ($item->status !== OaUsers::LEAVED): ?>
                                    <a href="<?=url('user/status/'.$item->user_id)?>?status=<?=OaUsers::LEAVED?>" class="btn btn-xs default ajax-link">
                                        <i class="fa fa-sign-out"></i> <?=__('Leaved')?>
                                    </a>
                                <? endif; ?>
                            </td>
                        </tr>
                        <? endforeach; ?>
                    </tbody>
                </table>
                <? partial_view('pagination/detail') ?>
            </div>
        </div>
    </div>
</div>
